<?php

declare (strict_types=1);

namespace App\Model;

use App\Library\Common;
use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\Database\Model\Relations\HasOne;

/**
 * @property int $id
 * @property int $shop_id
 * @property int $delivery_type
 * @property int $send_type
 * @property string $send_address
 * @property string $send_link
 * @property string $send_phone
 * @property string $receive_address
 * @property string $receive_link
 * @property string $receive_phone
 * @property string $order_sn
 * @property string $logistics_sn
 * @property string $logistics_name
 * @property int $create_time
 * @property int $send_time
 * @property int $poll_id
 */
class FlyShopDelivery extends Model
{
    public $timestamps = false;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'fly_shop_delivery';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'shop_id' => 'integer', 'delivery_type' => 'integer', 'send_type' => 'integer', 'create_time' => 'integer', 'send_time' => 'integer', 'poll_id' => 'integer'];

    /**
     * @return HasMany
     */
    public function with_poll_log()
    {
        return $this->hasMany(PollLog::class, 'id', 'poll_id')
            ->with('com_info')
            ->leftJoin('fly_delivery_send_order_log', 'fly_poll_log.order_sn', '=', 'fly_delivery_send_order_log.order_sn')
            ->select(['fly_delivery_send_order_log.status', 'fly_delivery_send_order_log.com', 'fly_delivery_send_order_log.num',
                'fly_delivery_send_order_log.id as send_id', 'fly_poll_log.id', 'time']);

//            ->orderBy('time', 'asc');
    }

    public function com_info()
    {
        return $this->belongsTo(Express::class,'com','code')->select(['code','url','logo','phone','name']);
    }

    /**
     * @return HasMany
     */
    public function with_log()
    {
        return $this->hasMany(DeliverySendOrderLog::class, 'num', 'num');
//            ->orderBy('time', 'asc');
    }


}